package com.example.wananrdroid.fragment;



import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;

import com.example.wananrdroid.Main2Activity;
import com.example.wananrdroid.R;
import com.example.wananrdroid.adapter.GuangAdapter;
import com.example.wananrdroid.base.BaseFragment;
import com.example.wananrdroid.bean.GuangBean;
import com.example.wananrdroid.presenter.GuangPresnter;
import com.example.wananrdroid.view.GuangView;

import java.util.ArrayList;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 */
public class GuangFragment extends BaseFragment<GuangPresnter> implements GuangView {

    @BindView(R.id.guang_re)
    RecyclerView mguang_re;
    @BindView(R.id.toolbar)
    Toolbar mtoolbar;
    private ArrayList<GuangBean.DataBean.DatasBean> datasBeans;
    private GuangAdapter guangAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mtoolbar.setTitle("");
        mguang_re.setLayoutManager(new LinearLayoutManager(getContext()));
        mguang_re.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayout.VERTICAL));
        datasBeans = new ArrayList<>();
        guangAdapter = new GuangAdapter(getContext(), datasBeans);
        mguang_re.setAdapter(guangAdapter);
        guangAdapter.setOnContextClickListener(new GuangAdapter.OnContextClickListener() {
            @Override
            public void oncontextclicklistener(View v, int position) {
                String link = datasBeans.get(position).getLink();
                Intent intent = new Intent(getContext(), Main2Activity.class);
                intent.putExtra("url",link);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void initPresenter() {
        mPresenter=new GuangPresnter();
        mPresenter.guangdata();
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_guang;
    }

    @Override
    public void onSuccess(GuangBean guangdata) {
        datasBeans.addAll(guangdata.getData().getDatas());
        guangAdapter.notifyDataSetChanged();
    }

    @Override
    public void onFali(String error) {

    }

    @Override
    public void showToast(String str) {

    }
}
